package com.youlu.campus.starter.trace.config;

import com.youlu.campus.starter.trace.filter.HttpTraceIdFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 过滤器配置
 *
 * @Description: FilterConfig
 * @Date 2025/6/23
 * @author: su
 */
@Configuration
public class FilterConfig {

    /**
     * 注册filter过滤器
     *
     * @return
     */
    @Bean
    public FilterRegistrationBean httpTraceIdFilterRegistration() {
        FilterRegistrationBean<HttpTraceIdFilter> registration = new FilterRegistrationBean<>();
        registration.setFilter(new HttpTraceIdFilter());
        registration.addUrlPatterns("/*");      // 拦截所有请求
        registration.setOrder(Integer.MIN_VALUE);  // 设置为最高优先级
        return registration;
    }
}
